import { _ as _export_sfc, x as useMainStore, y as storeToRefs, z as ref, A as computed, B as onLoad, a1 as navigateTo, R as onPullDownRefresh, aa as onReachBottom, a5 as showLoading, W as stopPullDownRefresh, a7 as hideLoading, c as createBlock, w as withCtx, i as index$g, j as resolveEasycom, k as resolveDynamicComponent, o as openBlock, b as createVNode, e as createCommentVNode, g as createElementBlock, F as Fragment, h as renderList, t as createTextVNode, u as toDisplayString, p as index$q, Q as index$x, M as withModifiers } from './index-Cc4oxzDN.js';
import { _ as __easycom_1 } from './uv-tabs.CwA-F7oh.js';
import { _ as __easycom_2 } from './list-cell.BHNnBKKp.js';
import { _ as __easycom_4 } from './uv-empty.ob-CT4XT.js';
import { o as orderGetOrders, a as orderReceive } from './order.D8qtvuIN.js';
import './uv-badge.D4nY_Rjy.js';
import './platform.EIa5ETLd.js';

const _sfc_main = {
  __name: 'order',
  setup(__props) {

	const main = useMainStore();
	const {
		isLogin
	} = storeToRefs(main);
	ref('我的订单');
	ref('');

	const page = ref(1);
	const pageSize = ref(10);
	const orders = ref([]);
	const tabList = ref([{
		type: -1,
		name: '全部',
	}, {
		type: 0,
		name: '待支付',
	}, {
		type: 1,
		name: '进行中'
	}, {
		type: 4,
		name: '已完成'
	}, {
		type: -3,
		name: '退款单'
	}]);
	const current = ref(0);
	const type = ref(-1);

	const goodsNum = computed(() => { //计算单个饮品添加到购物车的数量
		return (goods) => {
			let num = 0;
			goods.forEach(good => num += parseInt(good.number));
			return num;
		}
	});
	ref(false);
	onLoad(() => {
		console.log("onLoad");
		if (!isLogin.value) {
			navigateTo({
				url: '/pages/login/login'
			});
		}

		getOrders(false);

	});

	onPullDownRefresh(() => {
		console.log("onPullDownRefresh");
		if (!isLogin.value) {
			navigateTo({
				url: '/pages/login/login'
			});
		}


		getOrders(true);


	});
	onReachBottom(() => {
		console.log("onReachBottom");
		if (!isLogin.value) {
			navigateTo({
				url: '/pages/login/login'
			});
		}


		getOrders(false);

	});


	// tab栏切换
	const change = (e) => {
		//console.log('e;',e.type)
		//console.log('e.index;',e.index)
		type.value = e.type;
		getOrders(true);
	};

	const getOrders = async (isRefresh = false) => {
		showLoading({
			title: '加载中'
		});
		try {
			if (isRefresh) {
				orders.value = [];
				page.value = 1;
			}

			let ordersData = await orderGetOrders({
				page: page.value,
				limit: pageSize.value,
				type: type.value
			});

			if (ordersData) {
				orders.value = orders.value.concat(ordersData);
				page.value += 1;
			}
			if (isRefresh) {
				stopPullDownRefresh();
			}
			hideLoading();
		} catch (e) {
			hideLoading();
		}
	};
	const detail = (id) => {
		navigateTo({
			url: '/pages/components/pages/orders/detail?id=' + id
		});
	};
	// 确认收到货
	const receive = async (order) => {
		let data = await orderReceive({
			uni: order.orderId
		});
		if (data) {
			await getOrders(true);
		}
	};

return (_ctx, _cache) => {
  const _component_uv_tabs = resolveEasycom(resolveDynamicComponent("uv-tabs"), __easycom_1);
  const _component_v_uni_view = index$g;
  const _component_list_cell = resolveEasycom(resolveDynamicComponent("list-cell"), __easycom_2);
  const _component_v_uni_image = index$q;
  const _component_v_uni_button = index$x;
  const _component_uv_empty = resolveEasycom(resolveDynamicComponent("uv-empty"), __easycom_4);

  return (openBlock(), createBlock(_component_v_uni_view, { class: "container" }, {
    default: withCtx(() => [
      createVNode(_component_v_uni_view, { class: "bg-white" }, {
        default: withCtx(() => [
          createVNode(_component_uv_tabs, {
            list: tabList.value,
            current: current.value,
            onChange: change,
            keyName: "name",
            scrollable: false
          }, null, 8, ["list", "current"])
        ]),
        _: 1
      }),
      createVNode(_component_v_uni_view, {
        class: "orders-list d-flex flex-column w-100",
        style: {"padding":"20rpx","padding-bottom":"0"}
      }, {
        default: withCtx(() => [
          (openBlock(true), createElementBlock(Fragment, null, renderList(orders.value, (item, index) => {
            return (openBlock(), createBlock(_component_v_uni_view, {
              class: "order-item",
              key: index,
              style: {"margin-bottom":"30rpx"}
            }, {
              default: withCtx(() => [
                createVNode(_component_list_cell, { hover: false }, {
                  default: withCtx(() => [
                    (item.orderType == 'franchisees')
                      ? (openBlock(), createBlock(_component_v_uni_view, {
                          key: 0,
                          class: "w-100 d-flex align-items-center"
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_v_uni_view, { class: "flex-fill d-flex flex-column" }, {
                              default: withCtx(() => [
                                createVNode(_component_v_uni_view, {
                                  class: "font-size-lg text-color-base",
                                  style: {"margin-bottom":"20rpx","flex-direction":"row","justify-content":"space-between","display":"flex"}
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(" 加盟商订单 ")
                                  ]),
                                  _: 1
                                }),
                                createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                  default: withCtx(() => [
                                    createTextVNode("订单编号：" + toDisplayString(item.orderId), 1)
                                  ]),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1024),
                            createVNode(_component_v_uni_view, { class: "font-size-lg text-color-primary" }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(item.statusDto.title), 1)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024))
                      : (openBlock(), createBlock(_component_v_uni_view, {
                          key: 1,
                          class: "w-100 d-flex align-items-center"
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_v_uni_view, { class: "flex-fill d-flex flex-column" }, {
                              default: withCtx(() => [
                                createVNode(_component_v_uni_view, {
                                  class: "font-size-lg text-color-base",
                                  style: {"margin-bottom":"20rpx"}
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode(toDisplayString((item.shop && item.shop.name !== undefined && item.shop.name !== null) ? item.shop.name : '无'), 1)
                                  ]),
                                  _: 2
                                }, 1024),
                                createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                  default: withCtx(() => [
                                    createTextVNode("取餐号：" + toDisplayString(item.numberId), 1)
                                  ]),
                                  _: 2
                                }, 1024),
                                createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                                  default: withCtx(() => [
                                    createTextVNode("订单编号：" + toDisplayString(item.orderId), 1)
                                  ]),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1024),
                            createVNode(_component_v_uni_view, { class: "font-size-lg text-color-primary" }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(item.statusDto.title), 1)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024))
                  ]),
                  _: 2
                }, 1024),
                createVNode(_component_list_cell, {
                  hover: false,
                  last: ""
                }, {
                  default: withCtx(() => [
                    createVNode(_component_v_uni_view, { class: "w-100 d-flex flex-column" }, {
                      default: withCtx(() => [
                        createVNode(_component_v_uni_view, {
                          class: "w-100 text-truncate font-size-lg text-color-base",
                          style: {"margin-bottom":"20rpx"}
                        }, {
                          default: withCtx(() => [
                            (openBlock(true), createElementBlock(Fragment, null, renderList(item.cartInfo, (good, index) => {
                              return (openBlock(), createBlock(_component_v_uni_view, {
                                class: "flex mb-2",
                                key: index
                              }, {
                                default: withCtx(() => [
                                  createVNode(_component_v_uni_image, {
                                    src: good.image,
                                    mode: "aspectFill",
                                    class: "image"
                                  }, null, 8, ["src"]),
                                  createVNode(_component_v_uni_view, { class: "flex flex-column" }, {
                                    default: withCtx(() => [
                                      createVNode(_component_v_uni_view, { class: "font-size-medium mt-1 text-color-base" }, {
                                        default: withCtx(() => [
                                          createTextVNode(toDisplayString(good.title), 1)
                                        ]),
                                        _: 2
                                      }, 1024),
                                      createVNode(_component_v_uni_view, { class: "font-size-sm mt-1" }, {
                                        default: withCtx(() => [
                                          createTextVNode(toDisplayString(good.spec), 1)
                                        ]),
                                        _: 2
                                      }, 1024),
                                      createVNode(_component_v_uni_view, { class: "font-size-sm mt-2" }, {
                                        default: withCtx(() => [
                                          createTextVNode("×" + toDisplayString(good.number) + " ¥" + toDisplayString(good.price), 1)
                                        ]),
                                        _: 2
                                      }, 1024)
                                    ]),
                                    _: 2
                                  }, 1024)
                                ]),
                                _: 2
                              }, 1024))
                            }), 128))
                          ]),
                          _: 2
                        }, 1024),
                        createVNode(_component_v_uni_view, {
                          class: "d-flex justify-content-between align-items-center",
                          style: {"margin-bottom":"30rpx"}
                        }, {
                          default: withCtx(() => [
                            createVNode(_component_v_uni_view, { class: "font-size-sm text-color-assist" }, {
                              default: withCtx(() => [
                                createTextVNode(toDisplayString(item.createTime), 1)
                              ]),
                              _: 2
                            }, 1024),
                            createVNode(_component_v_uni_view, { class: "d-flex font-size-sm text-color-base align-items-center" }, {
                              default: withCtx(() => [
                                createVNode(_component_v_uni_view, { style: {"margin-right":"10rpx"} }, {
                                  default: withCtx(() => [
                                    createTextVNode("共" + toDisplayString(goodsNum.value(item.cartInfo)) + "件商品，实付", 1)
                                  ]),
                                  _: 2
                                }, 1024),
                                createVNode(_component_v_uni_view, { class: "font-size-lg" }, {
                                  default: withCtx(() => [
                                    createTextVNode("￥" + toDisplayString(item.payPrice), 1)
                                  ]),
                                  _: 2
                                }, 1024)
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024),
                        createVNode(_component_v_uni_view, { class: "d-flex align-items-center justify-content-end" }, {
                          default: withCtx(() => [
                            createVNode(_component_v_uni_view, null, {
                              default: withCtx(() => [
                                (item.paid > 0 && item.status < 2 && item.refundStatus == 0 && (item.orderType === 'takeout'))
                                  ? (openBlock(), createBlock(_component_v_uni_button, {
                                      key: 0,
                                      class: "left-margin",
                                      plain: "",
                                      size: "min",
                                      onClick: withModifiers($event => (receive(item)), ["stop"])
                                    }, {
                                      default: withCtx(() => [
                                        createTextVNode("确认收到餐 ")
                                      ]),
                                      _: 2
                                    }, 1032, ["onClick"]))
                                  : createCommentVNode("", true),
                                createVNode(_component_v_uni_button, {
                                  class: "left-margin",
                                  plain: "",
                                  size: "min",
                                  onClick: $event => (detail(item.orderId))
                                }, {
                                  default: withCtx(() => [
                                    createTextVNode("订单详情")
                                  ]),
                                  _: 2
                                }, 1032, ["onClick"])
                              ]),
                              _: 2
                            }, 1024)
                          ]),
                          _: 2
                        }, 1024)
                      ]),
                      _: 2
                    }, 1024)
                  ]),
                  _: 2
                }, 1024)
              ]),
              _: 2
            }, 1024))
          }), 128))
        ]),
        _: 1
      }),
      (orders.value.length == 0)
        ? (openBlock(), createBlock(_component_uv_empty, {
            key: 0,
            mode: "order"
          }))
        : createCommentVNode("", true)
    ]),
    _: 1
  }))
}
}

};
const order = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId',"data-v-c2615566"]]);

export { order as default };
